//
//  MineViewController.m
//  Mine
//
//  Created by 宁宁 on 16/9/12.
//  Copyright © 2016年 宁宁. All rights reserved.
//

#import "MineViewController.h"

#import "MineHeaderView.h"//headerView
#import "MineElseTableViewCell.h"//cell

#import "FansCenterViewController.h"//粉丝中心
#import "AddressManagerViewController.h"//地址管理

#define ElseCellTitle @[@"我的邀请人", @"粉丝中心", @"我的二维码", @"我的个人推广网站", @"我的订单", @"地址管理"]

@interface MineViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MineViewController
{
    MineHeaderView *_headerView;
}

 static NSString *const MineElseTableViewCellID = @"MineElseTableViewCell";
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self registerTableView];
}

#pragma mark === 注册TableView ===
- (void)registerTableView{
    _headerView = [[[NSBundle mainBundle] loadNibNamed:@"MineHeaderView" owner:nil options:nil] lastObject];
    _headerView.frame = CGRectMake(0, 0, WIDTH, 908);
    [self setHeaderView];
    [self headerViewClick];
    self.tableView.tableHeaderView = _headerView;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MineElseTableViewCell" bundle:nil] forCellReuseIdentifier:MineElseTableViewCellID];
}

- (void)setHeaderView{
//    _headerView.headImg setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>  //头像
//    _headerView.nickName.text = //昵称
//    _headerView.Id.text = [NSString stringWithFormat:@"ID:"]//ID
//    _headerView.rank.text = [NSString stringWithFormat:@"当前等级K"]//等级
//    _headerView.numOfLineUp.text = [NSString stringWithFormat:@"参与排队人数"]//参与排队人数
//    _headerView.refreshTime.text = [NSString stringWithFormat:@"刷新时间"]//刷新时间
    
//    _headerView.doudou.text = //豆豆
//    _headerView.jindou.text = //金豆
//    _headerView.yindou.text = //银豆
//    _headerView.ledou.text = //乐豆
    
//    _headerView.teamSearch.text = //团队搜呗
//    _headerView.personalSearch.text = //个人搜呗
//    _headerView.teamPercent.text = [NSString stringWithFormat:@"%"]//团队搜呗百分比
    _headerView.teamPercentWidth.constant = 0.7 * (WIDTH - 1) / 2;//团队搜呗百分比
//    _headerView.personalPercent.text = //个人搜呗百分比
    _headerView.personalPercentWidth.constant = 0.3 * (WIDTH - 1) / 2;//个人搜呗百分比
    
//    _headerView.totalRevenue.text = //总收益
//    _headerView.withdraw.text = //可提现
//    _headerView.rangerReward.text = //游侠奖
//    _headerView.createrReward.text = //创客奖
//    _headerView.angleReward.text = //天使奖
//    _headerView.heroReward.text = //英雄奖
//    _headerView.marsReward.text = //战神奖
//    _headerView.giantReward.text = //巨人奖
}

- (void)headerViewClick{
    _headerView.headerViewCilck = ^(int a, int b){
        switch (a) {
            case 0:
            {
                //点击头像
            }
                break;
            case 1:
            {
                if (b == 0) {
                    //豆豆
                }else if (b == 1){
                    //金豆
                }else if (b == 2){
                    //银豆
                }else{
                    //乐豆
                }
            }
                break;
            case 2:
            {
                if (b == 0) {
                    //团队搜呗
                }else{
                    //个人搜呗
                }
            }
                break;
            case 3:
            {
                if (b == 0) {
                    //充值
                }else if (b == 1){
                    //抢金豆
                }else if (b == 2){
                    //账单明细
                }else{
                    //提现
                }
            }
                break;
            case 4:
            {
                if (b == 0) {
                    //总收益
                }else{
                    //可提现
                }
            }
                break;
            case 5:
            {
                if (b == 0) {
                    //游侠奖
                }else if (b == 1){
                    //创客奖
                }else if (b == 2){
                    //天使奖
                }else if (b == 3){
                    //英雄奖
                }else if (b == 4){
                    //战神奖
                }else{
                    //巨人奖
                }
            }
                break;
            default:
                break;
        }
    };
}

#pragma mark === TableViewDelegate ===
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 54;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MineElseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MineElseTableViewCellID];
    
    cell.imageicon.image = [UIImage imageNamed:[NSString stringWithFormat:@"wo%ld",(long)indexPath.row]];
    cell.title.text = ElseCellTitle[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%@", ElseCellTitle[indexPath.row]);
    switch (indexPath.row) {
        case 0:
            //我的邀请人
            break;
        case 1:
            //粉丝中心
        {
            FansCenterViewController *fans = [[FansCenterViewController alloc] init];
            fans.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:fans animated:YES];
        }
            break;
        case 2:
            //我的二维码
            break;
        case 3:
            //我的个人推广网站
            break;
        case 4:
            //我的订单
            break;
        case 5:
            //地址管理
        {
            AddressManagerViewController *address = [[AddressManagerViewController alloc] init];
            address.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:address animated:YES];
        }
            break;
        default:
            break;
    }
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,20, WIDTH, HEIGHT - 20 - 45)style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = RGBACOLOR(36, 34, 47, 1);
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end
